package com.itheima.set;

import java.util.Comparator;
import java.util.TreeSet;

public class TreeSetDemo02 {
    public static void main(String[] args) {
        TreeSet<Teacher> teachers = new TreeSet<>((o1, o2) -> {
            int result = o1.getAge()-o2.getAge();
            result = result == 0 ? o1.getName().compareTo(o2.getName()) : result;
            return result;
        });

        teachers.add(new Teacher("zs",10));
        teachers.add(new Teacher("ls",12));
        teachers.add(new Teacher("ww",14));
        teachers.add(new Teacher("zl",14));

        System.out.println(teachers);

    }
}

class Teacher {
    private String name;
    private Integer age;

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Teacher(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public Teacher() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
    }

